/*
 * @Date: 2023-02-16 10:50:12
 * @LastEditTime: 2023-03-31 14:03:38
 * @FilePath: /NLK/src/api/module/balance.ts
 * 介绍:
 */
import { defaHttp, ApiRes } from "../index";

/**获取游戏余额 */
export async function apiCoinGameBalance(
  data: CoinGameBalance.Req
): Promise<void | CoinGameBalance.Res> {
  const res = await defaHttp.post<ApiRes<CoinGameBalance.Res>>(
    "/wallet/get_balance",
    data
  );
  if (res.code !== 200) return;
  return res.data;
}
/**获取游戏余额 */
export namespace CoinGameBalance {
  export interface Req {
    coin_id: Id;
  }
  export interface Res {
    /**
     * 示例：80.0030
     */
    /**游戏余额 */
    availbale: string;
    /**
     * 示例：0
     */
    could: number;
  }
}

/**申请提币 */
export async function apiWithdrawCoin(
  data: WithdrawCoin.Req
): Promise<boolean> {
  const res = await defaHttp.post<ApiRes<WithdrawCoin.Res>>(
    "/wallet/withdraw",
    data,
    { mode: ["showError", "showSucceed", "showLoading"] }
  );
  if (res.code !== 200) return false;
  return true;
}
/**申请提币 */
export namespace WithdrawCoin {
  export interface Req {
    /**数量 */
    number: number;
    /**币种id */
    coin_id: StrNumber;
  }
  export type Res = void;
}

/**申请兑换 */
export async function apiExchange(data: Exchange.Req): Promise<boolean> {
  const res = await defaHttp.post<ApiRes<Exchange.Res>>(
    "/exchange/insert",
    data,
    { mode: ["showError", "showSucceed", "showLoading"] }
  );
  if (res.code !== 200) return false;
  return true;
}
/**申请兑换 */
export namespace Exchange {
  export interface Req {
    /**数量 */
    number: number;
    /**发送币种id */
    from_id: StrNumber;
    /**接收币种id */
    to_id: StrNumber;
  }
  export type Res = void;
}

/**检查币种授权状态 */
export async function apiAutoState(
  data: AutoState.Req
): Promise<void | AutoState.Res> {
  const res = await defaHttp.post<ApiRes<AutoState.Res>>("/auth/check", data);
  if (res.code !== 200) return;
  return res.data;
}
/**检查币种授权状态 */
export namespace AutoState {
  export interface Req {
    /**用户地址 */
    address: string;
    coin_id: StrNumber;
  }
  export interface Res {
    /**0未绑定；1绑定 */
    status: number;
  }
}
